/**
 * Created by Administrator on 2016-11-03.
 */
var cardMap;// 通过卡号和刷卡查询到的数据
var jsessionids = $.cookie('jsessionids');
var hy_vaa01;
var memberSettingData = {};
$(document).ready(function()
{
	 /**参数设置 */
    loadMemberSetting = function () {
        var values = [], views = [];
        views.push("programid||'_'||productid||'_'||paramno as key,value");
        values.push({productid: 1, programid: 116001, paramno: 2}); // 充值打印
        values.push({productid: 1, programid: 116001, paramno: 18});// 是否允许输入卡号
        values.push({productid: 1, programid: 116001, paramno: 14});// 对未入库的卡发卡
        values.push({productid: 1, programid: 116001, paramno: 4}); // 退卡时是否退押金
        values.push({productid: 1, programid: 116001, paramno: 13});// 是否退除工本费
        values.push({productid: 1, programid: 116001, paramno: 12});// 退除工本费的金额
        values.push({productid: 1, programid: 116001, paramno: 17});// 是否必须输入密码
        values.push({productid: 1, programid: 116001, paramno: 16});// 密码长度
        values.push({productid: 1, programid: 116001, paramno: 22});// 禁用基本账户
        values.push({productid: 1, programid: 116001, paramno: 21});// 禁止修改押金
        values.push({productid:1,programid:116001,paramno:72});// 获取读卡器接口地址
        values.push({productid:1,programid:116001,paramno:100});//身份证读卡器接口地址
        values.push({productid:1,programid:116001,paramno:79});//医保卡是否当就诊卡用

        $.ajax({
            url: memberUrl + '/his/common/query/batchGetSysParamJsonp',
//            url: 'http://192.168.1.156:8080/rateweb/cloud/his/common/query/batchGetSysParamJsonp',
            data: {
                'values': JSON.stringify(values),
                'views': JSON.stringify(views),
                jsessionids: $.cookie('jsessionids')
            },
            type: 'get',
            cache: false,
            async: false,
            dataType: 'jsonp',
            success: function (data) {
                debugger;
                //数组格式化成对象 如：{"103010_100_37":"2","103010_100_36":"2"}
                for (var i = 0, len = data.list.length; i < len; i++) {
                    memberSettingData[data.list[i].key] = data.list[i].value;
                }
            }
        });
    };
    loadMemberSetting();
    
});

//卡号输入框事件
function swingCard(type){
	$("#please_swing_card").on("change", function()
			{// 请刷卡
				debugger;
				var cardNumber = $(this).val();
				if (cardNumber)
				{
					ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
					{
					cardNumber : cardNumber,
					state : 1,
					jsessionids : jsessionids
					}, function(json)
					{
						if (json)
						{
							hy_vaa01 = vaa01;
							if (json.vcb12 == 2)
							{
								debugger;
								cardMap = json;
								$("#swing_card .swing-card-info").removeClass("hidden");
								$("#swing_card .swing-card-btn").removeClass("hidden");
								$("#name").text(json.vaa05);
								$("#cardNum").text(json.vcb04);
								$("#cardIssTime").text(moment(json.vcb16).format("YYYY-MM-DD HH:mm:ss"));
								$("#validTime").text(moment(json.vcb17).format("YYYY-MM-DD"));
								$("#accountNum").text(json.vbu03);
								$("#balance").text(json.vbu14);
								$("#plase_shuaKa").hide();
								var obj = {};
								obj.pass = $("#please_swing_card").val();
								obj.type = type;
								obj.layer = '';
								afterCardItem(obj);
							}
							else
							{
								if (json.vcb12 == 0)
								{
									$("#error_promptmess").text("无效卡，该卡(" + cardNumber + ")在系统中已建卡.");
								}
								else if (json.vcb12 == 1)
								{
									$("#error_promptmess").text("无效卡，该卡(" + cardNumber + ")在系统中已制卡.");
								}
								else if (json.vcb12 == 3)
								{
									$("#error_promptmess").text("无效卡，该卡(" + cardNumber + ")在系统中已挂失.");
								}
								else if (json.vcb12 == 4)
								{
									$("#error_promptmess").text("无效卡，该卡(" + cardNumber + ")在系统中已注销.");
								}
								else if (json.vcb12 == 5)
								{
									$("#error_promptmess").text("无效卡，该卡(" + cardNumber + ")在系统中已作废.");
								}
							}
						}
						else
						{
							layer.alert("此卡没有登记，请发卡后在刷卡！",
							{
								icon : 2
							});
							return;
						}
					});
				}
				else
				{
					layer.alert("卡号不能为空！",
					{
						icon : 2
					});
					return;
				}
			});
}



var sk_window;
// 打开刷卡窗口
function newCardOut(type)
{
	debugger;
	laytplUrl(hosturl + "/tpl/huiyuan_shuaka.html", {}, function(data, html)
	{
		sk_window = layer.open(
		{
		type : 1,
		shadeClose : true,// 点击弹出层外关闭弹出层
		shade : false,
		zIndex : 9999,
		area : [
		'560px', '400px'
		],
		maxmin : false, // 开启最大化最小化按钮
		title : "会员卡信息", // 界面设置
		content : html, // 捕获的元素
		success : function(layero, index)
		{
			swingCard(type);
			if(memberSettingData['116001_1_18'] == '1'){
                $("#shuaka_pronum").hide();
            }else{
                $("#shuaka_pronum").show();
            }
			// $(".swing-card-info").addClass("hidden");
			// $(".swing-card-btn").addClass("hidden");
			// $("#plase_shuaKa").show();
			$("#please_swing_card").focus();
			$("#please_swing_card").val('');
			$("#error_promptmess").text("");
			$("#remove_shuaka").click(function()
			{
				layer.close(sk_window);
			});
			$("#shuaka_pronum").on("click", function()
			{
				promptCard(type);
			});
//			$("#shuaka_queding").on("click",function(){
//				cardSearch();
//			});
			
		}
		});

	});

}
function  readMemberShipCard(){
	debugger;
	   if(memberSettingData['116001_1_72'] && memberSettingData['116001_1_72'] != ''){
		   $.ajax({
		        type: "get",
		        async: true,
		        url:memberSettingData['116001_1_72'],
		        dataType: "jsonp", 
		        processData: false,
		        jsonp:"callback",
				jsonpCallback:"success_jsonpCallback",
		        success: function (cardObj) {
		        	 var  cardNumber = cardObj.CardNo;
		        	 if(cardNumber && cardNumber !='无卡'  && cardNumber.indexOf("错误") < 0 ){
		        		 if(cardNumber){
		        			 searchShuaPromVal(cardNumber);
		        			 
		        		 }else{
		        			 layer.msg('刷卡失败！', {
		        					time : 2000,
		        					icon : 0,
		        					skin : 'layui-layer-msg0'
		        				}); 
		        		 }
		        	 }else{
		        		 layer.msg("读取卡号为空,请检查读卡器或会员卡！",{icon:2,skin:'layui-layer-msg2'});
		        	 }
		        },
		        error: function (XMLHttpRequest, textStatus, errorThrown) {
		        	layer.alert('请求出现错误,请检查接口地址！',{icon:2,skin:'layui-layer-msg2'});
		        }
		  });;
	   }else{
		   layer.msg("参数没有配置读卡器接口地址！",{icon:2,skin:'layui-layer-msg2'});
	   }
} 

//刷卡之后业务分支
function afterCardItem(obj){
	var type = obj.type;
	if (type == 1)
	{
		searchShuaPromVal(obj);
		$("#shuaka_queding").on("click",function(){
			cardSearch();
		});
	}
	else if (type == 2)//发送扣费交易
	{
		searchShuaPromVal_jiaoyi(obj);
	}
	else if (type == 3)//刷卡检索病人信息
	{
		searchShuaPromVal_guahao(obj);
	}
	else if (type == 4)//挂号扣费
	{
		searchShuaPromVal_guahaocharge(obj);
	}
	else if (type == 5)//诊金扣费
	{
		searchShuaPromVal_zhenjincharge(obj);
	}
}
var indexCardNumber;
function promptCard(type)
{
	indexCardNumber = layer.prompt(
	{
	title : '请输入卡号',
	formType : 0,
	maxlength : 20,
	yes : function(index, layero)
	{
		if ($(".layui-layer-input").val().length <= 20)
		{
			var obj = {};
			obj.pass = $(".layui-layer-input").val();
			obj.type = type;
			obj.layer = indexCardNumber;
			afterCardItem(obj);
//			afterCardItem(type,indexCardNumber);
		}
		else
		{
			layer.alert("最多输入20个字符！",
			{
			icon : 0,
			end : function(index)
			{
				$(".layui-layer-input").focus();
//				promptCard(type);
			}
			})
			return;

		}	
		
	},
	success : function(index, layero)
	{
		$(".layui-layer-input").focus();
		
	},
	end : function(index, layero)
	{
		$("#please_swing_card").focus();
	}
	});
}

/**
 * 交易窗口
 */
var jiaoyi_window
function jiaoyi()
{
	layer.close(indexCardNumber);
	layer.close(sk_window);
	laytplUrl(myurl + "/module/jiaoyi_html.html",{}, function(data, html) {
				jiaoyi_window = layer.open({
					type : 1,
					title : "交易窗口",
					area : [ "400px", "450px" ],
					shade : 0.1,
					content : html,
					closeBtn : 1,
					success : function(layero, index)
					{
						// 会员卡消费信息赋值
						$("#yukou_e").val(totalVbi);
						$("#jifen").val($("#vbu17").text());
						$("#kahao").val($("#vipId").text());
						$("#yu_e").val($("#vbu14").text());
						$("#vbu09").focus();
						// 密码校验
						return $("#vbu09").val();
					}
				})

			});
}
/**
 * 挂号交易
 */
function guahao_jiaoyi()
{
	layer.close(indexCardNumber);
	layer.close(sk_window);
	laytplUrl(myurl + "/module/guahao_jiaoyi_html.html",{}, function(data, html) {
		jiaoyi_window = layer.open({
			type : 1,
			title : "交易窗口",
			area : [ "400px", "450px" ],
			shade : 0.1,
			content : html,
			closeBtn : 1,
			success : function(layero, index)
			{
				// 会员卡消费信息赋值
				$("#yukou_e").val(totalVbi);
				$("#jifen").val(cardMap.vbu17);
				$("#kahao").val(cardMap.vcb04);
				$("#yu_e").val(cardMap.vbu14);
				$("#vbu09").focus();
				// 密码校验
				return $("#vbu09").val();
			},
			cancel:function()
			{
				totalVbi = 0;
			}
		})
		
	});
}

/**
 * 诊金交易
 */
function zhenjin_jiaoyi()
{
	layer.close(indexCardNumber);
	layer.close(sk_window);
	laytplUrl(myurl + "/module/zhenjin_jiaoyi_html.html",{}, function(data, html) {
		jiaoyi_window = layer.open({
			type : 1,
			title : "交易窗口",
			area : [ "400px", "450px" ],
			shade : 0.1,
			content : html,
			closeBtn : 1,
			success : function(layero, index)
			{
				// 会员卡消费信息赋值
				$("#yukou_e").val(totalVbi);
				$("#jifen").val(cardMap.vbu17);
				$("#kahao").val(cardMap.vcb04);
				$("#yu_e").val(cardMap.vbu14);
				$("#vbu09").focus();
				// 密码校验
				return $("#vbu09").val();
			},
			cancel:function()
			{
				totalVbi = 0;
			}
		})
		
	});
}

function removeAction_jiaoyi()
{
    totalVbi = 0;
	layer.close(jiaoyi_window);
}

function searchShuaPromVal(indexCardNumber)
{
		ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
		{
		cardNumber : indexCardNumber,
		jsessionids : jsessionids
		}, function(json)
		{
			if (json)
			{
				if (json.vcb12 == 2)
				{
					if(memberSettingData['116001_1_17']=="1"){
                        $(".swing-card-btn button").attr('disabled',true);
                        /*parent.isFocus=false;*/
                        pleaseProPwd(json,indexCardNumber);
                    }else{
                    	initDataHuiYuan(json);
                    }
				}
				else
				{
					if (json.vcb12 == 0)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
					}
					else if (json.vcb12 == 1)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已制卡.");
					}
					else if (json.vcb12 == 3)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
					}
					else if (json.vcb12 == 4)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
					}
					else if (json.vcb12 == 5)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
					}
					layer.close(indexCardNumber);
				}
				// findTopicName(661,1,json.vcb04,$("#jieshoumessage").val());
			}
			else
			{
				layer.close(indexCardNumber)
				layer.alert("会员卡号不存在或没有关联的会员卡！",
				{
					icon : 2
				});
			}
		});
}
//会员卡赋值---医保卡当就诊卡刷界面赋值
function initDataHuiYuan(json){
	$('#gh_vaa05').val(json.vaa05);
	$('#vaa02').val(json.vcb04);
	$("#vaa10").val(json.vaa10);
	$("#abw02").val(json.abw02);
	$("#gh_vaa01").val(json.vaa01);
	$("#vaa03").val(json.vaa03);
	$("#vaa03_1").val(json.vaa03);
	$('#vaa15').val(json.vaa15);
	$('#vaa35').val(json.vaa35);
	$('#bep06b').val(json.bep06b ? json.bep06b : 0);
	$('#vac57').val(json.vac57);
	$('#vac46').val(json.vac46);
	$('#ack01').val(json.ack01);
	$('#vac16').val(json.vac16);
	$('#abc02').val(json.abc02);
	$('#aau01').val(json.aau01);
	$('#vbu01').val(json.vbu01);
	$('#vbu14').val(json.vbu14 ? json.vbu14 : 0);
	$('#vbu15').val(json.vbu15 ? json.vbu15 : 0);
	$('#vbu30').val(json.vbu30 ? json.vbu30 : 0);
	if (json.vaa12 != "undefined")
	{
		$('#vaa12').val(moment(json.vaa12).format("YYYY-MM-DD HH:mm:ss"));
	}
	else
	{
		$('#vaa12').val(moment(new Date()).format("YYYY-MM-DD HH:mm:ss"));
	}
	$('#bdp02').val(json.bdp02).trigger("change"); 

// $("#gh_vaa05").val();
//	 //年龄
//	 $("#vaa10").val();
//	 //出生日期
//	 $("#vaa12").val();
//	 //身份证号
//	 $("#vaa15").val();
//	 //保险号
//	 $("#iak05").val();
//	 //保险卡号
//	 $("#iak04").val();
//	 //医保金额
//	 $("#iar33").val();
//	 //单位编码
//	 $("#iar12").val();
}

/**
 * 挂号界面刷卡查询病人信息
 * 
 * @param indexCardNumber
 */
function searchShuaPromVal_guahao(obj)
{
	debugger;
	var indexCardNumber = obj.indexCardNumber
	var pass = obj.pass;
	if (pass)
	{
		ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
		{
		cardNumber : pass,
		jsessionids : jsessionids
		}, function(json)
		{
			if (json)
			{
				if (json.vcb12 == 2)
				{
					cardMap = json;
//					$("#swing_card .swing-card-point").addClass("hidden");
//					$("#swing_card .swing-card-info").removeClass("hidden");
//					$("#swing_card .swing-card-btn").removeClass("hidden");
//					$("#name").text(json.vaa05);
//					$("#cardNum").text(json.vcb04);
//					$("#cardIssTime").text(moment(json.vcb16).format("YYYY-MM-DD HH:mm:ss"));
//					$("#validTime").text(moment(json.vcb17).format("YYYY-MM-DD"));
//					$("#accountNum").text(json.vbu03);
//					$("#balance").text(json.vbu14);
//					$("#plase_shuaKa").hide();
//					$("#shuaka_queding").on("click",function(){queryPatientInfo();});
					layer.close(indexCardNumber);
					queryPatientInfo();
					
				}
				else
				{
					if (json.vcb12 == 0)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
					}
					else if (json.vcb12 == 1)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已制卡.");
					}
					else if (json.vcb12 == 3)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
					}
					else if (json.vcb12 == 4)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
					}
					else if (json.vcb12 == 5)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
					}
					layer.close(indexCardNumber);
				}
				// findTopicName(661,1,json.vcb04,$("#jieshoumessage").val());
			}
			else
			{
				layer.close(indexCardNumber)
				layer.alert("会员卡号不存在或没有关联的会员卡！",
				{
					icon : 2
				});
			}
		});
	}
	else
	{
		layer.msg('卡号不能为空！',
		{
			icon : 2
		});

	}
}

//
function queryPatientInfo()
{
	layer.close(sk_window);
	$('#gh_vaa05').val(cardMap.vaa05);
	debugger;
	$('#gh_vaa01').val(cardMap.vaa01);
	$('#vaa02').val("");
	$("#vaa10").val(cardMap.vaa10);
	$("#abw02").val(cardMap.abw02);
	$("#vaa01").val(cardMap.vaa01);
	$("#vaa03").val(cardMap.vaa03);
	$('#vaa15').val(cardMap.vaa15);
	$('#vaa35').val(cardMap.vaa35);
	$('#bep06b').val(cardMap.bep06b == "null" ? 0 : cardMap.bep06b);
	$('#vac57').val(cardMap.vac57);
	$('#vac46').val(cardMap.vac46);
	$('#ack01').val(cardMap.ack01);
	$('#vac16').val(cardMap.vac16);
	$('#abc02').val(cardMap.abc02);
	$('#aau01').val(cardMap.aau01);
	var vaa12Value = cardMap.vaa12;
	$('#vbu01').val(0);
	$('#vbu14').val("");
	$('#vbu15').val("");
	$('#vbu30').val("");
	if (vaa12Value != "undefined")
	{
		$('#vaa12').val(moment(vaa12Value).format("YYYY-MM-DD HH:mm:ss"));
	}
	else
	{
		$('#vaa12').val(moment(new Date()).format("YYYY-MM-DD HH:mm:ss"));
	}
	$('#bdp02').val(cardMap.bdp02).trigger("change");
}


/*******************************刷身份证**************************************************************/


var  radIdent=true;
function readIdentityNumber(){
	debugger;
  if(memberSettingData['116001_1_100'] && memberSettingData['116001_1_100'] != ''){
   $.ajax({
        type: "get",
        async: true,
        url:memberSettingData['116001_1_100'],
        dataType: "jsonp", 
        processData: false,
        jsonp:"callback",
        jsonpCallback:"success_jsonpCallback",
        success: function (cardObj) {
        	 if(cardObj){
        		 if(cardObj.result != 'sucess'){
	        		 layer.msg(cardObj.CardNo,{icon:2,skin:'layui-layer-msg2'});
        			 $("#ReadCard").attr("disabled",false);
        			 return;
	        	 }
        	 }else{
        		 layer.msg('身份证信息数据为空！',{icon:2,skin:'layui-layer-msg2'});
    			 $("#ReadCard").attr("disabled",false);
    			 return;
        	 }
        	 if(cardObj.CardNo && cardObj.CardNo.indexOf("请把身份证放在阅读器上") < 0){
        		 if(cardObj.CardNo && !isNaN(cardObj.CardNo)){
	        		 ajaxGetJsonp(hostUrl+ "/member/memberManger/queryMemberByNumber",{cardNumber:cardObj.CardNo,state:1},function(json) {
	     				if (json != null) {
	     			  		if(json.vcb12 == 2){
	     			  			if(memberSettingData['116001_1_17']=="1"){
	    							isFocus=false;
	    							pleaseProPwd(json);
	    						}else{
		    							searchShuaPromVal(cardObj.CardNo);
		    							 $("#gh_vaa05").val(cardObj.Name);
		    							 $("#abw01").val(cardObj.Sex_Code).trigger("change");
		    							 $("#vaa10").val(cardObj.Age);
		    							 $("#aau01").val(cardObj.Age_Code).trigger("change");
		    							 $("#vaa12").val(cardObj.BirthDate);
		    							//	  $("#vaa10").val(cardObj.Age);
		    							//	  $("#aau01").val(cardObj.Age_Code).trigger("change");
		    							 $("#abq02").val(cardObj.Nation_Name).trigger("change");
		    							 $("#vac19").val(cardObj.Address);
		    							 $("#vaa15").val(cardObj.CardNo);
	    						}
	     			  		}else{
	     			  			if(json.vcb12 == 0){
	     			  				layer.alert("无效卡，该卡("+cardNumber+")在系统中已建卡(未开卡).",{icon:2,skin:'layui-layer-msg2'});
	    						}else if(json.vcb12 == 1){
	    							layer.alert("无效卡，该卡("+cardNumber+")在系统中已制卡.",{icon:2,skin:'layui-layer-msg2'});
	    						}else if(json.vcb12 == 3){
	    							layer.alert("无效卡，该卡("+cardNumber+")在系统中已挂失.",{icon:2,skin:'layui-layer-msg2'});
	    						}else if(json.vcb12 == 4){
	    							layer.alert("无效卡，该卡("+cardNumber+")在系统中已注销.",{icon:2,skin:'layui-layer-msg2'});
	    						}else if(json.vcb12 == 5){
	    							layer.alert("无效卡，该卡("+cardNumber+")在系统中已作废.",{icon:2,skin:'layui-layer-msg2'});
	    						}
	     			  		}
	     				}else{
	     					layer.alert("无效卡，该卡("+cardObj.CardNo+")没有在系统中登记.",{icon:2,skin:'layui-layer-msg2'});
//	    					layer.msg("无效卡，该卡("+cardNumber+")没有在系统中登记.",{icon:2,skin:'layui-layer-msg2'});
	     				}
	        		 });	
	        	 }else{
	        		 layer.msg("读取卡号为空,请检查读卡器或会员卡！",{icon:2,skin:'layui-layer-msg2'});
	        	 }
        	 }else{
        	  layer.msg("读取读取身份证失败,请检查读卡器或身份证是否放在读卡器上！",{icon:2,skin:'layui-layer-msg2'});
        	 }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        	layer.alert('请求出现错误,请检查身份证接口地址！',{icon:2,skin:'layui-layer-msg2'});
        },
        complete: function(data,status){  
                }   
  });;
   }else{
   layer.msg("参数没有配置身份证读卡器接口地址！",{icon:2,skin:'layui-layer-msg2'});
   }
}








function searchShuaPromVal_jiaoyi(obj)
{
	var indexCardNumber = obj.indexCardNumber;
	var pass = obj.pass;
	if (pass)
	{
		ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
		{
		cardNumber : pass,
		jsessionids : jsessionids
		}, function(json)
		{
			if (json)
			{
				if (json.vcb12 == 2)
				{
					cardMap = json;
					$("#swing_card .swing-card-point").addClass("hidden");
					$("#swing_card .swing-card-info").removeClass("hidden");
					$("#swing_card .swing-card-btn").removeClass("hidden");
					layer.close(indexCardNumber);
					jiaoyi();
				}
				else
				{
					if (json.vcb12 == 0)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
					}
					else if (json.vcb12 == 1)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已制卡.");
					}
					else if (json.vcb12 == 3)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
					}
					else if (json.vcb12 == 4)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
					}
					else if (json.vcb12 == 5)
					{
						$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
					}
					layer.close(indexCardNumber);
				}
			}
			else
			{
				layer.close(indexCardNumber)
				layer.alert("会员卡号不存在或没有关联的会员卡！",
				{
					icon : 2
				});
			}
		});
	}
	else
	{
		layer.msg('卡号不能为空！',
		{
			icon : 2
		});
	}
}
function searchShuaPromVal_guahaocharge(obj)
{
	debugger;
	var indexCardNumber = obj.indexCardNumber
	var pass = obj.pass;
//	var pass = $(".layui-layer-input").val();
	if (pass)
	{
		ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
				{
			cardNumber : pass,
			jsessionids : jsessionids
				}, function(json)
				{
					if (json)
					{
						if (json.vcb12 == 2)
						{
							cardMap = json;
							$("#swing_card .swing-card-point").addClass("hidden");
							$("#swing_card .swing-card-info").removeClass("hidden");
							$("#swing_card .swing-card-btn").removeClass("hidden");
							layer.close(indexCardNumber);
							guahao_jiaoyi();
						}
						else
						{
							if (json.vcb12 == 0)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
							}
							else if (json.vcb12 == 1)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已制卡.");
							}
							else if (json.vcb12 == 3)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
							}
							else if (json.vcb12 == 4)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
							}
							else if (json.vcb12 == 5)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
							}
							layer.close(indexCardNumber);
						}
					}
					else
					{
						layer.close(indexCardNumber)
						layer.alert("会员卡号不存在或没有关联的会员卡！",
								{
							icon : 2
								});
					}
				});
	}
	else
	{
		layer.msg('卡号不能为空！',
				{
			icon : 2
				});
	}
}
function searchShuaPromVal_zhenjincharge(obj)
{
	var indexCardNumber = obj.indexCardNumber
	var pass = obj.pass;
	if (pass)
	{
		ajaxGet(memberUrl + "/member/memberManger/queryMemberByNumber",
				{
			cardNumber : pass,
			jsessionids : jsessionids
				}, function(json)
				{
					if (json)
					{
						if (json.vcb12 == 2)
						{
							cardMap = json;
							$("#swing_card .swing-card-point").addClass("hidden");
							$("#swing_card .swing-card-info").removeClass("hidden");
							$("#swing_card .swing-card-btn").removeClass("hidden");
							layer.close(indexCardNumber);
							zhenjin_jiaoyi();
						}
						else
						{
							if (json.vcb12 == 0)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
							}
							else if (json.vcb12 == 1)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已制卡.");
							}
							else if (json.vcb12 == 3)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
							}
							else if (json.vcb12 == 4)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
							}
							else if (json.vcb12 == 5)
							{
								$("#error_promptmess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
							}
							layer.close(indexCardNumber);
						}
					}
					else
					{
						layer.close(indexCardNumber)
						layer.alert("会员卡号不存在或没有关联的会员卡！",
								{
							icon : 2
								});
					}
				});
	}
	else
	{
		layer.msg('卡号不能为空！',
				{
			icon : 2
				});
	}
}

var cz_window;
// 打开充值窗口
function rechargeCardOut()
{// 打开充值弹出框
	if (!cardMap)
	{
		layer.alert("会员数据加载出错,数据不存在！",
		{
			icon : 2
		});
		return;
	}
	cz_window = layer
			.open(
			{
			type : 2,
			shadeClose : true,// 点击弹出层外关闭弹出层
			shade : false,
			zIndex : 9999,
			area : [
			'1250px', '700px'
			],
			maxmin : false, // 开启最大化最小化按钮
			title : "会员充值", // 界面设置
			cancel : function()
			{

			},
			content : [
				memberHostUrl + '/jsp/member/chong_zhi.jsp?jsessionids=' + jsessionids + "&jieshoumessage=" + selectName + "&msgName=" + msgName + "&flag=2&cardMap=" + encodeURIComponent(JSON
						.stringify(cardMap))
			], // 捕获的元素

			});

}
// 打开退费弹出框
function returnCostOut()
{
	if (!cardMap)
	{
		layer.alert("会员数据加载出错,数据不存在！",
		{
			icon : 2
		});
		return;
	}
	cz_window = layer
			.open(
			{
			type : 2,
			shadeClose : true,// 点击弹出层外关闭弹出层
			shade : false,
			zIndex : 9999,
			area : [
			'1250px', '700px'
			],
			maxmin : false, // 开启最大化最小化按钮
			title : "会员退费", // 界面设置
			cancel : function()
			{

			},
			content : [
				memberHostUrl + '/jsp/member/tui_fei.jsp?jsessionids=' + jsessionids + "&jieshoumessage=" + selectName + "&msgName=" + msgName + "&flag=2&cardMap=" + encodeURIComponent(JSON
						.stringify(cardMap))
			], // 捕获的元素

			});
}
// 打开退卡弹出框
function card_RefundedOut()
{
	if (!cardMap)
	{
		layer.alert("会员数据加载出错,数据不存在！",
		{
			icon : 2
		});
		return;
	}
	cz_window = layer
			.open(
			{
			type : 2,
			shadeClose : true,// 点击弹出层外关闭弹出层
			shade : false,
			zIndex : 9999,
			area : [
			'1250px', '700px'
			],
			maxmin : false, // 开启最大化最小化按钮
			title : "会员退卡", // 界面设置
			cancel : function()
			{

			},
			content : [
				memberHostUrl + '/jsp/member/tui_ka.jsp?jsessionids=' + jsessionids + "&jieshoumessage=" + selectName + "&msgName=" + msgName + "&flag=2&cardMap=" + encodeURIComponent(JSON
						.stringify(cardMap))
			], // 捕获的元素

			});
}

// 打开会员更改密码出框
function revisePasswordOut()
{
	if (!cardMap)
	{
		layer.alert("会员数据加载出错,数据不存在！",
		{
			icon : 2
		});
		return;
	}
	cz_window = layer
			.open(
			{
			type : 2,
			shadeClose : true,// 点击弹出层外关闭弹出层
			shade : false,
			zIndex : 9999,
			area : [
			'1250px', '700px'
			],
			maxmin : false, // 开启最大化最小化按钮
			title : "会员更改密码", // 界面设置
			cancel : function()
			{

			},
			content : [
				memberHostUrl + '/jsp/member/xiu_gai_mi_ma.jsp?jsessionids=' + jsessionids + "&jieshoumessage=" + selectName + "&msgName=" + msgName + "&flag=2&cardMap=" + encodeURIComponent(JSON
						.stringify(cardMap))
			], // 捕获的元素
			success : function(layero, index)
			{
				var body = layer.getChildFrame('body', index);
				body.find('#revise_password .modal-foot .btn-white').click(function()
				{
					layer.close(index);
				});
			}
			});
}

// 发卡
// 打开发卡弹出框口
var newSwingCardindex;
function NewSwingCardOut()
{
	/*newSwingCardindex = layer.open(
	{
	type : 1,
	shadeClose : true,// 点击弹出层外关闭弹出层
	shade : false,
	zIndex : 9999,
	area : [
	'560px', '400px'
	],
	maxmin : false, // 开启最大化最小化按钮
	title : "会员卡信息", // 界面设置
	cancel : function()
	{
		$("#cover").addClass("hidden");
	},
	content : $('#new_swing_card'), // 捕获的元素
	success : function(layero, index)
	{
		$("#cover").removeClass("hidden");
		$("#creditcard").val('');
		$("#creditcard").focus();
		$("#plase_faKa").show();
		$("#error_mess").text("");
		$("#new_swing_card .modal-foot .btn-white").click(function()
		{
			$("#cover").addClass("hidden");
			layer.close(newSwingCardindex);
		});
	}
	});*/

}

function promptFaCard()
{
	var indexpromptFaCard = layer.prompt(
	{
	title : '请输入卡号',
	formType : 0,
	maxlength : 20,
	yes : function(index, layero)
	{
		searchFaPromVal(indexpromptFaCard);
	},
	success : function(index, layero)
	{
		$(".layui-layer-input").focus();
		$(".layui-layer-input").on('keyup', function(e)
		{
			if ($(this).val().length <= 20)
			{
				if (e.keyCode == 13)
				{
					searchFaPromVal(indexpromptFaCard);
				}
			}
			else
			{
				layer.alert("最多输入20个字符！",
				{
				icon : 0,
				end : function(index)
				{
					promptFaCard();
				}
				})

			}
		});
	},
	end : function(index, layero)
	{
		$("#creditcard").focus();
	}
	});
}

function searchFaPromVal(indexpromptFaCard)
{
	var pass = $(".layui-layer-input").val();
	if (pass)
	{
		ajaxGet(memberUrl + "/member/memberManger/queryCardObject",
		{
		vcb04 : pass,
		jsessionids : jsessionids
		}, function(json)
		{
			if (json != null)
			{
				$("#swing_card .swing-card-point").addClass("hidden");
				$("#swing_card .swing-card-info").removeClass("hidden");
				$("#swing_card .swing-card-btn").removeClass("hidden");
				if (json.vcb12 == 1)
				{
					faKaOut(json);
					layer.close(newSwingCardindex);
				}
				else
				{
					if (json.vcb12 == 0)
					{
						$("#error_mess").text("无效卡，该卡(" + pass + ")在系统中已建卡.");
					}
					else if (json.vcb12 == 2)
					{
						$("#error_mess").text("无效卡，该卡(" + pass + ")在系统中已发卡.");
					}
					else if (json.vcb12 == 3)
					{
						$("#error_mess").text("无效卡，该卡(" + pass + ")在系统中已挂失.");
					}
					else if (json.vcb12 == 4)
					{
						$("#error_mess").text("无效卡，该卡(" + pass + ")在系统中已注销.");
					}
					else if (json.vcb12 == 5)
					{
						$("#error_mess").text("无效卡，该卡(" + pass + ")在系统中已作废.");
					}
				}
				layer.close(indexpromptFaCard);
			}
			else
			{
				layer.close(indexpromptFaCard)
				layer.alert("会员卡号不存在！",
				{
					icon : 2
				});
			}
		});
	}
	else
	{
		layer.msg('卡号不能为空！',
		{
			icon : 2
		});

		return;
	}
}

// 打开发卡页面
var faKaOutindex
function faKaOut(json)
{// 打开发卡弹出框
	layer.close(newSwingCardindex);// 关闭请刷卡；
	faKaOutindex = layer
			.open(
			{
			type : 2,
			shadeClose : true,// 点击弹出层外关闭弹出层
			shade : false,
			zIndex : 9999,
			area : [
			'1250px', '750px'
			],
			maxmin : false, // 开启最大化最小化按钮
			title : "会员发卡", // 界面设置
			cancel : function()
			{
				parent.$("#cover").addClass("hidden");
			},
			content : [
				memberHostUrl + '/jsp/member/fa_ka.jsp?jsessionids=' + jsessionids + "&jieshoumessage=" + selectName + "&msgName=" + msgName + "&flag=2&cardMap=" + encodeURIComponent(JSON
						.stringify(json))
			], // 捕获的元素
			success : function(layero, index)
			{
				$("#cover").removeClass("hidden");
				/*
				 * var body = layer.getChildFrame('body', index); if(json !=
				 * null){ body.find('#vcb01').val(json.vcb01);
				 * body.find('#vcb02').val(json.vcb02);
				 * body.find('#vcb03').val(json.vcb03);
				 * body.find('#vcb04').val(json.vcb04);
				 * body.find('#vcb05').val(json.vcb05);
				 * body.find('#deviceid').val(json.deviceid);
				 * body.find('#bce01').val(json.bce01);
				 * body.find('#bce03').val(json.bce03);
				 * body.find('#vcb12').val(json.vcb12);
				 * body.find('#vcb15').val(moment(json.vcb15).format("YYYY-MM-DD"));
				 * body.find('#vcb16').val(json.vcb16);
				 * body.find('#vcb17').val(moment(json.vcb17).format("YYYY-MM-DD"));
				 * body.find('#empid').val($.cookie('employeeId'));
				 * body.find('#empno').val($.cookie('loginName'));
				 * body.find('#empname').val($.cookie('trueName')); }
				 * body.find('#new_card .modal-foot
				 * .btn-white').click(function(){ layer.close(faKaOutindex);
				 * parent.$("#cover").addClass("hidden"); });
				 */
			}
			});
}
$(function()
{
	$('#hy_sk_qd').click(function()
	{
		if ($('#wait-execute-tab').hasClass('active'))
		{
			// 待执行病人
			getWaitExecuteDataByHycode();
		}
		else
		{
			// 已完成病人
			getHasBeenCompletedDataByHycode();
		}
		layer.close(sk_window);
	})

});

function pleaseProPwd(json,indexCardNumber){
    var indexpleaseProPwd=layer.prompt({
        title: '验证会员密码',
        formType: 0,
        maxlength:20,
        success:function(index, layero){
            $(".layui-layer-input").attr('placeholder','请输入密码');
            $(".layui-layer-input").focus();
            $(".layui-layer-input").on('keyup',function(e){
                if(e.keyCode==13){
                    searchPwd(json,indexpleaseProPwd);
                }
            });
        },yes: function(index, layero){
            searchPwd(json,indexpleaseProPwd);

        },end:function(index, layero){

        },cancel:function(index, layero){
            $("#error_promptmess").text('请输入会员账号密码');
            /*parent.isFocus = true;*/
            $("#please_swing_card").focus();
        },
        btn2:function(index, layero){
            $("#error_promptmess").text('请输入会员账号密码');
            /*parent.isFocus = true;*/
            $("#please_swing_card").focus();
        },
    });
}
function searchPwd(json,indexpleaseProPwd){
    var pass=$(".layui-layer-input").val();
    $.get(rootUrl + "/clidoctor/getMD5PassWord",{password:pass},function(word) {
        if(json.vbu09==word.pass){
            $(".swing-card-btn button").attr('disabled',false);
            cardMap = json;
            $("#swing_card .swing-card-point").addClass("hidden");
            $("#swing_card .swing-card-info").removeClass("hidden");
            $("#swing_card .swing-card-btn").removeClass("hidden");
            $("#name").text(json.vaa05);
            $("#cardNum").text(json.vcb04);
            $("#cardIssTime").text(moment(json.vcb16).format("YYYY-MM-DD HH:mm:ss"));
            $("#validTime").text(moment(json.vcb17).format("YYYY-MM-DD"));
            $("#accountNum").text(json.vbu03);
            $("#balance").text(json.vbu14);
            $("#plase_shuaKa").hide();
           /* btnContArrFun()*/
            layer.close(indexpleaseProPwd);
        }else{
            layer.close(indexpleaseProPwd);
            layer.alert("会员账号密码输入错误！",{icon:2,end:function(index){
                pleaseProPwd(json,indexpleaseProPwd);
            }})
        }
    });
}


